package com.book.Dao;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Addserverle extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String id=request.getParameter("id");
		String bname=request.getParameter("bname");
		String image_w=request.getParameter("image_w");
		String image_b=request.getParameter("image_b");
		String price=request.getParameter("price");
		String author=request.getParameter("author");
		String press=request.getParameter("press");
		String publishtime=request.getParameter("publishtime");
		String pid=request.getParameter("pid");
		String fenlei=null;
		if("1".equals(pid)){
			fenlei="小说故事";
		}else if("2".equals("学习资料")){
			fenlei="小说故事";
		}else{
			fenlei="IT书籍";
		}
		System.out.println(id+bname+image_w+image_b+price+author+press+publishtime+pid+fenlei);
		
	   Connection conn=null;
  	   Statement stm=null;
  	   String sql="insert into book (BOOKID,BOOKNAME,CHUBANSHE,ZUOZHE,BOOKTIME,PRICE,CUTERGERY,FENLEIID,BOOKIMG,BOOKIMG2)values("+id+",'"+bname+"','"+press+"','"+author+"',to_date('"+publishtime+"','yyyy-MM-dd'),"+price+",'"+fenlei+"',"+pid+",'../book_img/"+image_w+"','../book_img/img/"+image_b+"')";
  	   try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","scott","tiger");
			stm=conn.createStatement();
			boolean x=stm.execute(sql);
			if(!x){
				response.sendRedirect("./houtaibook/BookManager.jsp");
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
